package com.wrk._3_方法._02_习题;

import java.util.Scanner;

public class _002_写一个计算器 {
    //实现加减乘除功能
    public static void main(String[] args) {
        //
        System.out.print("请输入进行加、减、乘、除中的那种运算：");
        //接收运算方式
        Scanner scanner = new Scanner(System.in);
        String calculationMethod = scanner.next();
        //判断
        switch (calculationMethod){
            case "加":
                System.out.print("请输入两个数字，以空格分隔："+"\t");
                double result1 = addition(scanner.nextDouble(),scanner.nextDouble());
                System.out.println("加法运算结果："+ result1);
                break;
            case "减":
                System.out.print("请输入两个数字，以空格分隔："+"\t");
                double result2 = subtraction(scanner.nextDouble(),scanner.nextDouble());
                System.out.println("减法运算结果："+ result2);
                break;
            case "乘":
                System.out.print("请输入两个数字，以空格分隔："+"\t");
                double result3 = multiplication(scanner.nextDouble(),scanner.nextDouble());
                System.out.println("乘法运算结果："+ result3);
                break;
            case "除":
                System.out.print("请输入两个数字，以空格分隔："+"\t");
                double result4 = division(scanner.nextDouble(),scanner.nextDouble());
                System.out.println("除法运算结果："+ result4);
                break;
            default:
                System.out.println("输入错误");
        }
    }
    //定义加法方法
    public static double addition(double number1,double number2){
        return number1 + number2;
    }
    //定义减法方法
    public static double subtraction(double number1,double number2){
        if( number1 > number2){
            return number1 - number2;
        } else if (number1 < number2) {
            return number2 - number1;
        }else {
            return 0;
        }
    }
    //定义乘法方法
    public static double multiplication(double number1,double number2){
        return number1 * number2;
    }
    //定义除法方法
    public static double division(double number1,double number2){
        return number1 / number2;
    }
}
